<?php
namespace Admin\Controller;

use Think\Controller;

class MainController extends Controller
{
    public function _initialize()
    {
        //判断用户是否已经登录
        if (!isset($_SESSION['username'])) {
            $this->error('对不起,您还没有登录!请先登录再进行操作', U('Index/index'), 1);
        }
    }

    public function config()
    {
        $Config = M('config');
        $data   = $Config->find(1);
        $this->assign('data', $data);
        $this->display();
    }

    public function upConfig()
    {
        $data['site']        = I('post.site');
        $data['code']        = I('post.code');
        $data['name']        = I('post.name');
        $data['mail']        = I('post.mail');
        $data['appkey']      = I('post.appkey');
        $data['appsecret']   = I('post.appsecret');
        $data['keyword']     = nl2br(trim($_POST['keyword']));
        $data['description'] = nl2br(trim($_POST['description']));
        $data['retime']      = time();
        $config              = M('config');
        $where['id']         = 1;
        $ret                 = $config->where($where)->save($data);
        $code                = $config->where($where)->find(1);
        F('appkeyappsecret', array('appkey' => $code['appkey'], 'appsecret' => $code['appsecret']));
        F('siteinfo', $code);

        if ($ret) {
            return show('1', '修改成功!');
        } else {
            return show('2', '修改失败!');
        }
    }

    public function goods()
    {
        $Api             = M('Api');
        $itemget         = $Api->find(1);
        $jutqgget        = $Api->find(2);
        $favoritesitemup = $Api->find(3);

        $this->assign(array(
            'itemget'         => $itemget,
            'jutqgget'        => $jutqgget,
            'favoritesitemup' => $favoritesitemup,

        ));

        $this->display();
    }

    //提交本项api设置
    public function upGoodsApi()
    {
        $info = I('post.');
        $Api  = D('GoodsApi');
        $ret  = $Api->upGoodsApi($info);
        if ($ret) {
            return show('1', '修改成功！');
        } else {
            return show('2', '修改失败！');
        }

    }

}
